import {DefaultUrlSerializer, UrlTree} from "@angular/router";
import {MenuJumpParam} from "@shared/model/erupt-menu";

/**
 * 自定义实现url编码，实现router进行矩阵参数的编码(默认会将矩阵参数进行encode)
 * Ajian 20221124
 */
export class CustomUrlSerializer extends DefaultUrlSerializer {
    private k1: string = '%3B' + MenuJumpParam.paramName + '%3D';
    private k2: string = '%3B' + MenuJumpParam.paramEntityAndPrimaryKey + '%3D';

    serialize(tree: UrlTree): string {
        //检查是否需要decode url
        let url = tree.toString();
        if (url.indexOf(this.k1) > -1 || url.indexOf(this.k2)) {
            return decodeURIComponent(url)
        }
        return super.serialize(tree);
    }
}
